from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-16 14:07:38.790949
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 16, Feb, 2022
Time: 14:07:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1333
Nobs: 569.000 HQIC: -48.5522
Log likelihood: 6713.00 FPE: 6.27490e-22
AIC: -48.8203 Det(Omega_mle): 5.36426e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.347592 0.068734 5.057 0.000
L1.Burgenland 0.106672 0.041795 2.552 0.011
L1.Kärnten -0.110972 0.021744 -5.104 0.000
L1.Niederösterreich 0.190147 0.087419 2.175 0.030
L1.Oberösterreich 0.133424 0.086181 1.548 0.122
L1.Salzburg 0.254410 0.044238 5.751 0.000
L1.Steiermark 0.036130 0.058346 0.619 0.536
L1.Tirol 0.100104 0.047067 2.127 0.033
L1.Vorarlberg -0.070471 0.041589 -1.694 0.090
L1.Wien 0.019910 0.076620 0.260 0.795
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053039 0.148344 0.358 0.721
L1.Burgenland -0.038406 0.090202 -0.426 0.670
L1.Kärnten 0.041197 0.046927 0.878 0.380
L1.Niederösterreich -0.201980 0.188669 -1.071 0.284
L1.Oberösterreich 0.460345 0.185997 2.475 0.013
L1.Salzburg 0.281520 0.095475 2.949 0.003
L1.Steiermark 0.113176 0.125924 0.899 0.369
L1.Tirol 0.304609 0.101581 2.999 0.003
L1.Vorarlberg 0.024420 0.089758 0.272 0.786
L1.Wien -0.028377 0.165362 -0.172 0.864
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199621 0.035094 5.688 0.000
L1.Burgenland 0.089051 0.021339 4.173 0.000
L1.Kärnten -0.007323 0.011102 -0.660 0.509
L1.Niederösterreich 0.237445 0.044633 5.320 0.000
L1.Oberösterreich 0.163087 0.044001 3.706 0.000
L1.Salzburg 0.040179 0.022587 1.779 0.075
L1.Steiermark 0.026636 0.029790 0.894 0.371
L1.Tirol 0.082024 0.024031 3.413 0.001
L1.Vorarlberg 0.054280 0.021234 2.556 0.011
L1.Wien 0.117021 0.039120 2.991 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121203 0.035043 3.459 0.001
L1.Burgenland 0.043462 0.021309 2.040 0.041
L1.Kärnten -0.013174 0.011086 -1.188 0.235
L1.Niederösterreich 0.169945 0.044569 3.813 0.000
L1.Oberösterreich 0.336838 0.043938 7.666 0.000
L1.Salzburg 0.100249 0.022554 4.445 0.000
L1.Steiermark 0.110464 0.029747 3.713 0.000
L1.Tirol 0.090466 0.023997 3.770 0.000
L1.Vorarlberg 0.060429 0.021204 2.850 0.004
L1.Wien -0.020070 0.039064 -0.514 0.607
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122509 0.066046 1.855 0.064
L1.Burgenland -0.046387 0.040160 -1.155 0.248
L1.Kärnten -0.045421 0.020893 -2.174 0.030
L1.Niederösterreich 0.137643 0.084000 1.639 0.101
L1.Oberösterreich 0.166021 0.082810 2.005 0.045
L1.Salzburg 0.283586 0.042508 6.671 0.000
L1.Steiermark 0.057151 0.056064 1.019 0.308
L1.Tirol 0.156076 0.045226 3.451 0.001
L1.Vorarlberg 0.096190 0.039962 2.407 0.016
L1.Wien 0.075583 0.073623 1.027 0.305
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080578 0.051479 1.565 0.118
L1.Burgenland 0.025432 0.031302 0.812 0.417
L1.Kärnten 0.053320 0.016285 3.274 0.001
L1.Niederösterreich 0.190897 0.065473 2.916 0.004
L1.Oberösterreich 0.329242 0.064545 5.101 0.000
L1.Salzburg 0.033686 0.033132 1.017 0.309
L1.Steiermark 0.005473 0.043699 0.125 0.900
L1.Tirol 0.120413 0.035251 3.416 0.001
L1.Vorarlberg 0.065716 0.031148 2.110 0.035
L1.Wien 0.097108 0.057385 1.692 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169599 0.062217 2.726 0.006
L1.Burgenland 0.004626 0.037832 0.122 0.903
L1.Kärnten -0.065889 0.019682 -3.348 0.001
L1.Niederösterreich -0.109193 0.079130 -1.380 0.168
L1.Oberösterreich 0.209760 0.078009 2.689 0.007
L1.Salzburg 0.053465 0.040043 1.335 0.182
L1.Steiermark 0.249175 0.052814 4.718 0.000
L1.Tirol 0.499624 0.042604 11.727 0.000
L1.Vorarlberg 0.065312 0.037645 1.735 0.083
L1.Wien -0.073359 0.069355 -1.058 0.290
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160364 0.068983 2.325 0.020
L1.Burgenland -0.004920 0.041946 -0.117 0.907
L1.Kärnten 0.062282 0.021822 2.854 0.004
L1.Niederösterreich 0.173245 0.087735 1.975 0.048
L1.Oberösterreich -0.057025 0.086492 -0.659 0.510
L1.Salzburg 0.205439 0.044398 4.627 0.000
L1.Steiermark 0.138202 0.058557 2.360 0.018
L1.Tirol 0.056083 0.047237 1.187 0.235
L1.Vorarlberg 0.144538 0.041739 3.463 0.001
L1.Wien 0.125119 0.076897 1.627 0.104
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393860 0.040442 9.739 0.000
L1.Burgenland -0.003584 0.024591 -0.146 0.884
L1.Kärnten -0.021416 0.012794 -1.674 0.094
L1.Niederösterreich 0.201078 0.051436 3.909 0.000
L1.Oberösterreich 0.229217 0.050707 4.520 0.000
L1.Salzburg 0.036882 0.026029 1.417 0.156
L1.Steiermark -0.017208 0.034330 -0.501 0.616
L1.Tirol 0.091245 0.027694 3.295 0.001
L1.Vorarlberg 0.050980 0.024470 2.083 0.037
L1.Wien 0.042003 0.045082 0.932 0.351
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036333 0.102018 0.168962 0.136508 0.096214 0.082021 0.032642 0.211128
Kärnten 0.036333 1.000000 -0.027617 0.132345 0.048294 0.085698 0.444303 -0.067396 0.089335
Niederösterreich 0.102018 -0.027617 1.000000 0.309923 0.118644 0.268353 0.064611 0.151865 0.286672
Oberösterreich 0.168962 0.132345 0.309923 1.000000 0.214438 0.293698 0.167691 0.135673 0.234790
Salzburg 0.136508 0.048294 0.118644 0.214438 1.000000 0.124660 0.091767 0.105038 0.124480
Steiermark 0.096214 0.085698 0.268353 0.293698 0.124660 1.000000 0.134368 0.105993 0.030854
Tirol 0.082021 0.444303 0.064611 0.167691 0.091767 0.134368 1.000000 0.063132 0.151521
Vorarlberg 0.032642 -0.067396 0.151865 0.135673 0.105038 0.105993 0.063132 1.000000 -0.005897
Wien 0.211128 0.089335 0.286672 0.234790 0.124480 0.030854 0.151521 -0.005897 1.000000